home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / keysortcltn.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  4KB  |  147 lines

  1. /* Test class KeySortCltn
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    keysortcltn.c,v $
  26.  * Revision 3.0  90/05/20  00:29:23  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/keysortcltn.c,v 3.0 90/05/20 00:29:23 kgorlen Rel $";
  31.  
  32. #include "KeySortCltn.h"
  33. #include "String.h"
  34. #include "Date.h"
  35. #include "Float.h"
  36. #include "Time.h"
  37. #include "Integer.h"
  38.  
  39. KeySortCltn c;
  40.  
  41. static void part1()
  42. {
  43.     c.addAssoc(*new String("A"),*new String("Ant"));
  44.     c.addAssoc(*new String("M"),*new String("Man"));
  45.     c.addAssoc(*new String("C"),*new String("Cat"));
  46.     c.addAssoc(*new String("E"),*new String("Emu"));
  47.     c.addAssoc(*new String("H"),*new Date(25,"Dec",85));
  48.     c.addAssoc(*new String("J"),*new Float(98.6));
  49.     c.addAssoc(*new String("E"),*new String("Eeyore"));
  50.     c.addAssoc(*new String("Z"),*new Time(Date(29,"Jan",63),21,30));
  51.  
  52.     c.printOn(cout); cout << endl;
  53.  
  54.     int k;
  55.     k = c.findIndexOf(String("A"));
  56.      cout << "index " << k << " before key A" << endl;
  57.     k = c.findIndexOf(String("M"));
  58.      cout << "index " << k << " before key M" << endl;
  59.     k = c.findIndexOf(String("C"));
  60.      cout << "index " << k << " before key C" << endl;
  61.     k = c.findIndexOf(String("E"));
  62.      cout << "index " << k << " before key E" << endl;
  63.     k = c.findIndexOf(String("Z"));
  64.      cout << "index " << k << " before key Z" << endl;
  65.     k = c.findIndexOf(String("F"));
  66.      cout << "index " << k << " before key F" << endl;
  67.     k = c.findIndexOf(String("@"));
  68.      cout << "index " << k << " before key @" << endl;
  69.     k = c.findIndexOf(String("["));
  70.      cout << "index " << k << " before key [" << endl;
  71.  
  72.     KeySortCltn clone = *KeySortCltn::castdown(c.copy());
  73.      cout << "clone isEqual c: " << c.isEqual(clone) << endl;
  74.      cout << "clone == c: " << (c == (clone)) << endl;
  75.      cout << "clone != c: " << (c != (clone)) << endl;
  76.      cout << "c.compare(clone) = " << c.compare(clone) << endl;
  77.      cout << "c.includesKey(String(\"J\")) = " << c.includesKey(String("J")) << endl;
  78.      cout << "c.includesKey(String(\"K\")) = " << c.includesKey(String("K")) << endl;
  79.      cout << "c.occurrencesOfKey(String(\"Q\")) = " << c.occurrencesOfKey(String("Q")) << endl;
  80.      cout << "c.occurrencesOfKey(String(\"M\")) = " << c.occurrencesOfKey(String("M")) << endl;
  81.      cout << "c.occurrencesOfKey(String(\"E\")) = " << c.occurrencesOfKey(String("E")) << endl;
  82.  
  83.     cout << "atKey(String(\"J\")) = " << *c.atKey(String("J"))
  84.          << endl;
  85.     cout << "atKey(String(\"N\")) = " << *c.atKey(String("N"))
  86.          << endl;
  87. }
  88.  
  89. static void part2()
  90. {
  91.     OrderedCltn o;
  92.     c.addValuesTo(o);
  93.     c.addKeysTo(o);
  94.     cout << "\nOrderedCltn o =" << endl;
  95.     cout << o << endl;
  96.  
  97.     SortedCltn b;
  98.     c.addContentsBeforeTo(String("E"), b);
  99.     cout << "\nSortedCltn b =" << endl;
  100.     cout << b << endl;
  101.  
  102.     cout << "*c.removeKey(String(\"Z\")) = " << *c.removeKey(String("Z")) << endl;
  103.     cout << "*c.removeKey(String(\"Q\")) = " << *c.removeKey(String("Q")) << endl;
  104.     cout << "*c.removeKey(String(\"E\")) = " << *c.removeKey(String("E")) << endl;
  105.     c.printOn(cout); cout << endl;
  106.  
  107.     const int ARRAY_SIZE = 4;
  108.     ArrayOb x(ARRAY_SIZE), y(ARRAY_SIZE), z(ARRAY_SIZE);
  109.     String s0("apple"), s1("bat"), s2("cat");
  110.     String s3("gopher"), s4("dog"), s5("eagle");
  111.  
  112.     int i;
  113.     for (i = 0; i < ARRAY_SIZE - 1; i++)
  114.         switch (i) {
  115.             case (0):
  116.                 x[i] = y[i] = z[i] = &s0;
  117.                 break;
  118.             case (1):
  119.                 x[i] = y[i] = z[i] = &s1;
  120.                 break;
  121.             case (2):
  122.                 x[i] = y[i] = z[i] = &s2;
  123.                 break;
  124.         } /* switch */
  125.  
  126.     x[ARRAY_SIZE - 1] = &s3;
  127.     y[ARRAY_SIZE - 1] = &s4;
  128.     z[ARRAY_SIZE - 1] = &s5;
  129.  
  130.     KeySortCltn d;
  131.  
  132.     d.addAssoc(x, Integer(0));
  133.     d.addAssoc(y, Integer(1));
  134.     d.addAssoc(z, Integer(2));
  135.     cout << endl; d.printOn(cout); cout << endl;
  136.     int k;
  137.     k = d.findIndexOf(y);
  138.      cout << "index "; y.printOn(cout); cout << "\nbefore key " << k << endl;
  139. }
  140.  
  141. main()
  142. {
  143.     cout << "\nTest class KeySortCltn" << endl;
  144.     part1();
  145.     part2();
  146. }
  147.